Skip to content

Conversation

@sadiqkhoja
Copy link
Contributor

@sadiqkhoja sadiqkhoja commented Nov 20, 2025

Closes getodk/central#1470

See the analysis of the issue at getodk/central#1470 (comment)

What has been done to verify that this works as intended?

Added couple of tests.

Why is this the best possible solution? Were any other approaches considered?

The bug about startIndex and endIndex in htmlparser2 mentioned in the previous comment has been fixed in the latest version so I thought it would be good to upgrade it and use startIndex and endIndex to replace/append version value.

We were using quite an old version of htmlparser2 i.e. v3.9 and the current version is v10.0. In one of our meeting we talked about using the latest versions of all dependencies where possible.

The upgrade is done in a separate PR to keep the changes for the actual bug fix minimum: #1692

To review this PR just see the latest commit.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

No

Does this change require updates to the API documentation? If so, please update docs/api.yaml as part of this PR.

No

Before submitting this PR, please make sure you have:

  • run make test and confirmed all checks still pass OR confirm CircleCI build passes
  • verified that any code from external sources are properly credited in comments or that everything is internally sourced

@sadiqkhoja sadiqkhoja marked this pull request as draft November 20, 2025 22:48
@sadiqkhoja sadiqkhoja force-pushed the fixes/html-entities-in-version branch from aab3983 to d9d27bf Compare November 20, 2025 22:59
@sadiqkhoja sadiqkhoja marked this pull request as ready for review November 21, 2025 19:33
@sadiqkhoja sadiqkhoja marked this pull request as draft December 4, 2025 16:40
@sadiqkhoja sadiqkhoja force-pushed the fixes/html-entities-in-version branch from d9d27bf to fc570d1 Compare December 5, 2025 04:17
Comment on lines 545 to 549
// okay, we have found the thing we are looking for.
// idx points at the position of the closing "
//
// TODO: we cheat here and reference the hp2 internal tokenizer index to find
// out where the attribute actually is. the parser startIndex and endIndex point
// at the whitespace preceding the tag until the tag is closed. obviously this is
// pretty bad but i don't see a more robust solution right now.
const idx = parser.tokenizer.index;
const result = replace
? `${xml.slice(0, parser.startIndex)}version="${insert}"${xml.slice(parser.endIndex)}`
: `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`;
parser.reset();
return replace
? pass(`${xml.slice(0, idx - value.length)}${insert}${xml.slice(idx)}`)
: pass(`${xml.slice(0, idx)}${insert}${xml.slice(idx)}`);
return pass(result);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

latest version has fixed the bug around startIndex and endIndex, so we can use that.

@sadiqkhoja sadiqkhoja marked this pull request as ready for review December 5, 2025 04:23
const idx = parser.tokenizer.index;
const result = replace
? `${xml.slice(0, parser.startIndex)}version="${insert}"${xml.slice(parser.endIndex)}`
: `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a subtle change here for the replace case. I think it introduces a bug in untested code paths.

Fix:

Suggested change
: `${xml.slice(0, parser.endIndex-1)}${insert}"${xml.slice(parser.endIndex)}`;
: `${xml.slice(0, parser.endIndex)}${insert}${xml.slice(parser.endIndex)}`;

Copy link
Contributor

@alxndrsn alxndrsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this aims to fix two separate bugs.

  1. The fix in lib/model/frames/form.js is tested in test/integration/api/forms/forms.js, and looks good, and I could approve immediately if submitted separately.
  2. The fix in lib/data/schema.js is tested in test/unit/data/schema.js, and looks like it introduces a surprising bug in an untested code path. I think my suggestion will fix that.

@sadiqkhoja
Copy link
Contributor Author

I have tried this change with frontend as well, encoding single and double quotes working as expected:

image

Copy link
Contributor

@alxndrsn alxndrsn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@sadiqkhoja sadiqkhoja merged commit c84c09e into getodk:master Dec 8, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

If the version name is too long, it cannot be changed in its entirety.

2 participants